public class num1022 {
    //从根到叶的二进制之和
    public int sumRootToLeaf(TreeNode root) {
        return dfs(root,0);
    }

    private int dfs(TreeNode root, int i) {
        if (root == null) {
            return 0;
        }
        i = (i << 1 | root.val);
        if(root.left == null && root.right == null) {
            return i;
        }
        return dfs(root.left,i) + dfs(root.right,i);
    }
}
